//
//  WithAnimationView.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/19.
//

import SwiftUI
// 显式动画 withAnimation
struct WithAnimationView: View {
  @State private var circleColorChange = false
  @State private var heartColorChange = false
  @State private var heartSizeChange = false
  var body: some View {
    Text("显式动画").font(.system(.largeTitle, design: .rounded, weight: .bold))
    ZStack {
      Circle()
        .frame(width: 200, height: 200)
        .foregroundStyle(circleColorChange ? Color(.systemGray5) : .red)

      Image(systemName: "heart.fill")
        .foregroundStyle(heartColorChange ? .red : .white)
        .font(.system(size: 100))
        .scaleEffect(heartSizeChange ? 1.0 : 0.5)
    }
    .onTapGesture {
//      withAnimation(.default) { }
      withAnimation(.spring(response: 0.3, dampingFraction: 0.3, blendDuration: 0.3)) {
        self.circleColorChange.toggle()
        self.heartColorChange.toggle()
        self.heartSizeChange.toggle()
      }
    }
  }
}

#Preview {
  WithAnimationView()
}
